package cube;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


class Cube {
    private double sideLength;

    // 构造方法
    public Cube(double sideLength) {
        this.sideLength = sideLength;
    }

    public double getVolume() {
        return Math.pow(sideLength, 3);
    }


    public double getSideLength() {
        return sideLength;
    }


    public void setSideLength(double sideLength) {
        this.sideLength = sideLength;
    }

    @Override
    public String toString() {
        return "Cube{" +
                "sideLength=" + sideLength +
                ", volume=" + getVolume() +
                '}';
    }
}

public class CubeSort {
    public static void main(String[] args) {
        List<Cube> cubes = new ArrayList<>();


        for (int i = 1; i <= 10; i++) {
            cubes.add(new Cube(i));
        }

        Collections.sort(cubes, (cube1, cube2) -> Double.compare(cube2.getVolume(), cube1.getVolume()));

        System.out.println("立方体按体积降序排列：");
        for (Cube cube : cubes) {
            System.out.println(cube);
        }
    }
}
